{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# `FForwardRewrite`\n",
    "\n",
    "源码：`tvm/include/tvm/relay/op_attr_types.h`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```C++\n",
    "/*!\n",
    " * \\brief Forward rewriting rule for a specific op.\n",
    " *\n",
    " * \\param ref_call The reference old call type to be rewritten.\n",
    " *                 We can make use of the op and type information.\n",
    " * \\param new_args The new arguments (some of them could be TempExpr).\n",
    " * \\param ctx  Optional context information about ref_call.\n",
    " * \\return The rewriten result call, can also return nullptr,\n",
    " *         which indicate the rewriter should use the default fallback\n",
    " *         rule that realizes all its input and compose the call.\n",
    " *\n",
    " * \\note When we register the function, we can register\n",
    " *       a different signature with ctx to be a specific node type.\n",
    " */\n",
    "using FForwardRewrite = runtime::TypedPackedFunc<Expr(\n",
    "    const Call& ref_call, const Array<Expr>& new_args, const ObjectRef& ctx)>;\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`FForwardRewrite` 是类型别名，它是一个带有类型的打包函数对象类型。这个函数对象的签名如下：\n",
    "\n",
    "```cpp\n",
    "Expr(const Call& ref_call, const Array<Expr>& new_args, const ObjectRef& ctx)\n",
    "```\n",
    "\n",
    "其中，`ref_call` 是一个引用类型的旧调用类型，用于被重写；`new_args` 是新的参数列表，其中一些可以是 `TempExpr`；`ctx` 是关于 `ref_call` 的可选的上下文信息。\n",
    "\n",
    "该函数返回一个重写后的结果调用，也可以返回空指针，表示重写器应该使用默认的回退规则来实现所有输入并组合调用。\n",
    "\n",
    "在注册此函数时，我们可以使用不同的签名和上下文信息来注册特定节点类型。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
